// 导入相关的组件
import Vue from 'vue'
import VueRouter from "vue-router";


//前台
import Login from "@/views/login/Login.vue";
import Enroll from "@/views/login/Enroll.vue";
import Front_Index from "@/views/front-end/Front_Index.vue";
import Front_GoodsAll from "@/views/front-end/Front_GoodsAll.vue";
import Carousel1 from "@/views/carousel/Carousel1.vue";
import Front_UsersInfo from "@/views/front-end/Front_UsersInfo.vue";
import Info from "@/views/front-end/user_info_bar/Info.vue";
import Businesses_info from "@/views/front-end/user_info_bar/Businesses_info.vue";
import Suppliers_Info from "@/views/front-end/user_info_bar/Suppliers_Info.vue";
import aa from "@/views/front-end/aa.vue";
import Front_Carts from "@/views/front-end/Front_Carts.vue";
import ProductDetail from "@/views/front-end/good/ProductDetail.vue";
import FrontSuppliersList from "@/views/front-end/suppliers/FrontSuppliersList.vue";
import SuppliersMaintenance from "@/views/front-end/suppliers/SuppliersMaintenance.vue";


//管理员
import HoTaiLogin from "@/views/login/HoTaiLogin.vue";
import HoTaiEnroll from "@/views/login/HoTaiEnroll.vue";
import administrator1 from "@/views/administrator/administrator1.vue";
import PublishGoods from "@/views/administrator/PublishGoods.vue";
import GoodsList from "@/views/administrator/GoodsList.vue";
import Home from "@/views/administrator/Home.vue";
import PurchaseApply from "@/views/administrator/PurchaseApply.vue";
import PurchaseReview from "@/views/administrator/PurchaseReview.vue";
import WarehouseInReview from "@/views/administrator/WarehouseInReview.vue";
import WarehouseInApply from "@/views/administrator/WarehouseInApply.vue";
import WarehouseOutApply from "@/views/administrator/WarehouseOutApply.vue";
import WarehouseOutReview from "@/views/administrator/WarehouseOutReview.vue";
import WarehouseList from "@/views/administrator/WarehouseList.vue";
import AddWarehouse from "@/views/administrator/AddWarehouse.vue";
import SupplierReview from "@/views/administrator/SupplierReview.vue";
import AddMerchant from "@/views/administrator/AddMerchant.vue";
import MerchantList from "@/views/administrator/MerchantList.vue";
import SupplierList from "@/views/administrator/SupplierList.vue";
import SuppliersOrderInfo from "@/views/front-end/suppliers/SuppliersOrderInfo.vue";
import SupplierInfo from "@/views/front-end/suppliers/SupplierInfo.vue";
import MerchantsInfo from "@/views/front-end/Merchants/MerchantsInfo.vue";
import MerchantsOrderInfo from "@/views/front-end/Merchants/MerchantsOrderInfo.vue";
import AddCarousel from "@/views/administrator/Carousel/AddCarousel.vue";
import CarouselInfo from "@/views/administrator/Carousel/CarouselInfo.vue";
import InfoClassify from "@/views/administrator/Classify/InfoClassify.vue";
import OrderManagement from "@/views/front-end/OrderManagement.vue";



//后台


// 注册路由组件
Vue.use(VueRouter)



const router = new VueRouter({
    routes: [
        //前台主页路由
        { path: '/', redirect: '/login'},
        { path:'/login' , component: Login},//登录
        { path:'/enroll' , component: Enroll},//注册
        {path:'/aa',component:aa},
        {path:'/front_index',component: Front_Index,redirect:'/carousel1',//首页
        children:[
            {path:'/carousel1',component:Carousel1},//轮播图
            {path:'/front_goodsAll',component:Front_GoodsAll,props:true},//全部商品
            {path: '/orderManagement',component: OrderManagement},//订单管理
            {path: '/front_carts',component: Front_Carts},
            {path:'/front_userInfo',component:Front_UsersInfo,redirect:'/info',
                children:[
                    {path:'/info',component:Info},//用户基本信息
                    {path:'/businesses_info',component:Businesses_info},//用户注册
                    {path:'/supplierInfo',component:SupplierInfo},//供应商基本信息
                    {path:'/merchantsInfo',component:MerchantsInfo},//商户基本信息
                    {path:'/merchantsOrderInfo',component:MerchantsOrderInfo},//商户订单管理


                    {path:'/suppliers_info',component:Suppliers_Info},//供应商注册
                    {path:'/suppliersOrderInfo',component:SuppliersOrderInfo},//供应商订单管理
                    {path:'/frontSuppliersList',component:FrontSuppliersList},//供货商报价
                    {path:'/suppliersMaintenance',component:SuppliersMaintenance},//供货商维护
                ]},//用户信息

            {path: '/productDetail/:proId',component: ProductDetail,props:true}//商品详情

        ]},
        {path:'/settlement',
            name:'Settlement',component:() =>import("@/views/front-end/good/Settlement.vue")
        },


        //管理员
        { path:'/hoTaiLogin' , component: HoTaiLogin},//管理员登录
        { path:'/hoTaiEnroll' , component: HoTaiEnroll},//注册
        {path:'/administrator1',component: administrator1,redirect:'/home',
        children:[
            {path: '/home',component:Home},//首页
            {path: '/publishGoods',component:PublishGoods},//发布商品
            {path: '/goodsList',component:GoodsList},//商品列表
            {path: '/purchaseApply',component:PurchaseApply},//采购申请
            {path: '/purchaseReview',component:PurchaseReview},//采购审核
            {path: '/warehouseInReview',component:WarehouseInReview},//仓库入库审核
            {path: '/warehouseInApply',component:WarehouseInApply},//仓库入库申请
            {path: '/warehouseOutApply',component:WarehouseOutApply},//仓库出库申请
            {path: '/warehouseOutReview',component:WarehouseOutReview},//仓库出库审核
            {path: '/warehouseList',component:WarehouseList},//仓库列表
            {path: '/addWarehouse',component:AddWarehouse},//添加仓库
            {path: '/supplierReview',component:SupplierReview},//供应商审核
            {path: '/supplierList',component:SupplierList},//供应商列表
            {path: '/addMerchant',component:AddMerchant},//添加商家
            {path: '/merchantList',component:MerchantList},//商家列表
            {path: '/addCarousel',component: AddCarousel},//轮播图的添加
            {path: '/carouselInfo',component: CarouselInfo},//轮播图列表
            {path: '/infoClassify',component: InfoClassify}//分类

        ]},

    ]
})

// // 导航守卫，验证用户是否登录
// router.beforeEach((to, from,next)=>{
//     // 思考：如果是多个相似的前端路由，可以使用正则表达式或者路径字符串的截取来判断是否放行
//     // 业务要求：前台网站首页，以及全部商品，单件商品的展示都要不登录也能访问
//     if(to.path === '/login' || to.path === '/enroll' || to.path === '/front_index')
//         return next()
//     else {
//         // 登录了才放行,没有登录不放行
//         const tokenStr = window.sessionStorage.getItem('token')
//         if(!tokenStr)
//             return next('/')
//         return next()
//     }
//
// })
export default router